package test.pbking.facebook.delegates
{
	import com.pbking.facebook.Facebook;
	import com.pbking.facebook.delegates.fbml.RefreshImgSrcDelegate;
	import com.pbking.facebook.delegates.fbml.RefreshRefUrlDelegate;
	import com.pbking.facebook.delegates.fbml.SetRefHandleDelegate;
	
	import flash.events.Event;
	
	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;
	
	import test.pbking.facebook.Facebook_test;

	public class Fbml_test extends TestCase
	{
		private static var facebook:Facebook;
		
		private var testHandle:String = "testHandle1";
		private var testHandleFbml:String = "testHandle1 value";
		
		/** randomly selected image url.  Any image url should work. */
		private var testImgSrc:String = "http://www.adobe.com/lib/com.adobe/template/gnav/adobe-hq.png";
		
		private var testRefUrl:String = "http://www.yahoo.com";
		
		
		public function Fbml_test(methodName:String=null)
		{
			super(methodName);
		}
		
		public static function suite(testFacebook:Facebook):TestSuite
		{
			facebook = testFacebook;
			
			var ts:TestSuite = new TestSuite();
			
			// Note: setRefHandle() does not work in desktopSession.  So this test has to be run in widgetSession.
			// Since FB_API_TEST.mxml uses desktopSession; comment out this test.  Uncomment when testing using WidgetSession.
			//ts.addTest( new Fbml_test("testSetRefHandle"));
			ts.addTest( new Fbml_test("testRefreshImgSrc"));
			ts.addTest( new Fbml_test("testRefreshRefUrl"));
			
			return ts;
		}
		
		/**
		 * Test setRefHandle().
		 * Note: setRefHandle() does not work in desktopSession.  So this test 
		 * has to be run in widgetSession.
		 */
		public function testSetRefHandle():void
		{
 			facebook.fbml.setRefHandle(testHandle, testHandleFbml, addAsync(testSetRefHandleReply, Facebook_test.timeoutTime));
		}
		private function testSetRefHandleReply(e:Event):void
		{
			var d:SetRefHandleDelegate = e.target as SetRefHandleDelegate;
			assertTrue(d.errorMessage, d.success);
		}
		
		/**
		 * Test testRefreshImgSrc()
		 */
		public function testRefreshImgSrc():void
		{
			facebook.fbml.refreshImgSrc(testImgSrc, addAsync(testRefreshImgSrcReply, Facebook_test.timeoutTime));
		}
		private function testRefreshImgSrcReply(e:Event):void
		{
			var d:RefreshImgSrcDelegate = e.target as RefreshImgSrcDelegate;
			assertTrue(d.errorMessage, d.success);
		}
		
		/**
		 * Test testRefreshRefUrl()
		 */
		public function testRefreshRefUrl():void
		{
			facebook.fbml.refreshRefUrl(testRefUrl, addAsync(testRefreshRefUrlReply, Facebook_test.timeoutTime));
		}
		private function testRefreshRefUrlReply(e:Event):void
		{
			var d:RefreshRefUrlDelegate = e.target as RefreshRefUrlDelegate;
			assertTrue(d.errorMessage, d.success);
		}
	}
}